package fun.flyee.android.pengshan.utils;

import android.content.Context;

import java.io.File;
import java.io.IOException;

public class UIUncompresser {

    public static Boolean exec(Context context) {
        File tempFolder = new File(context.getFilesDir(), "tmp");
        if (!tempFolder.exists()) {
            tempFolder.mkdir();
        }
        File uiFolder = new File(context.getFilesDir(), "ui");
//        if (BuildConfig.DEBUG) {
            Files.deleteChildrenFiles(uiFolder);
//        }
        if (!uiFolder.exists()) {
            uiFolder.mkdir();
        }
        File indexFile = new File(uiFolder, "index.html");
        if (indexFile.exists()) return true;
        try {
            Files.unzip(context.getAssets().open("ui.zip"), uiFolder);
            return true;
        } catch (IOException e) {
            Logger.e("Uncompress UI error", e);
            return false;
        }
    }

}
